package com.zking.frame.ZC;

import java.sql.Connection;
import java.sql.DriverManager;//加载驱动
import java.sql.ResultSet;
import java.sql.Statement;
public class JDBC {
	public static String url ="jdbc:mysql://localhost:3306/studentmessage?useUnicode=true&characterEncoding=UTF-8";
    public static String driver ="com.mysql.jdbc.Driver";
	public static String user = "root";
	public static String password = "root";
    static {
	//加载驱动
	try {
		Class.forName(driver);
	} catch (Exception e) {
		e.printStackTrace();
	}
//建立连接
}
public static Connection getConnection() {
	Connection conn=null;
try {
	conn=DriverManager.getConnection(url,user,password);
} catch (Exception e) {
	// TODO: handle exception
}
return  conn;
}
public static void closeResource(Connection conn, Statement st, ResultSet rs) {
	try {
		if (conn != null) {
			conn.close();
		}
		if (st != null) {
			st.close();
		}
		if (rs != null) {
			rs.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
public static void closeResource(Connection conn, Statement st) {
	try {
		if (conn != null) {
			conn.close();
		}
		if (st != null) {
			st.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
public static void main(String[] args) {
	System.out.println(JDBC.getConnection());
}
}
